from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User

class CustomUserAdmin(UserAdmin):
    list_display = ('username', 'name', 'email', 'gender', 'is_admin', 'is_superuser', 'login_count', 'last_login', 'created_at')
    list_filter = ('is_admin', 'is_superuser', 'gender', 'is_active')
    search_fields = ('username', 'name', 'email')
    ordering = ('-created_at',)
    
    readonly_fields = ('created_at', 'updated_at', 'last_login', 'login_count', 'ip_address')
    
    fieldsets = (
        ('基本信息', {'fields': ('username', 'password', 'name', 'email', 'gender', 'phone')}),
        ('权限信息', {'fields': ('is_active', 'is_admin', 'is_staff', 'is_superuser')}),
        ('其他信息', {'fields': ('last_login', 'login_count', 'ip_address', 'created_at', 'updated_at')}),
    )
    
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('username', 'password1', 'password2', 'name', 'email', 'gender', 'phone'),
        }),
    )

admin.site.register(User, CustomUserAdmin)
